<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SitioController
 *
 * @author Nayeli
 */
class SitioController extends AppController
{
    var $uses = array('Shipment','Route');
    var $components = array('Session','Email');
   
    
    public function beforeFilter()
    {
        parent::beforeFilter();
    }

    public function index()
    {
        $this->set('title_for_layout', 'Inicio');
        
 
        $limit=5;
        $this->Route->routesList($limit);
        $this->Shipment->shipmentsList($limit);

        $this->set('routesDetails', $this->Route->routesList($limit));
        $this->set('shipmentsDetails', $this->Shipment->shipmentsList($limit));
    }
    
    public function quienes()
    {
        $this->set('title_for_layout', '¿Qui&eacute;nes Somos?'); 
        $this->layout = 'base';
        $imagen = 'banner/masfletes_10.jpg';
        $altima = 'MasFletes_¿Quiénes Somos?';
        $this->set('imagen',$imagen);
        $this->set('altima',$altima);
    }

    public function servicios()
    {
        $this->set('title_for_layout', 'Servicios');
        $this->layout = 'base';
        $imagen = 'banner/masfletes_2.jpg';
        $altima = 'Masfletes_Servicios';
        $this->set('imagen',$imagen);
        $this->set('altima',$altima);
    }
    
    public function enlaces()
    {
        $this->set('title_for_layout', 'Enlaces');
        $this->layout = 'base';
        $imagen = 'banner/masfletes_4.jpg';
        $altima = 'MasFletes_Enlaces_Interesantes';
        $this->set('imagen',$imagen);
        $this->set('altima',$altima);
    }
    
    public function articulos()
    {
        $this->set('title_for_layout', 'Art&iacute;culos');
        $this->layout = 'base';
        $imagen = 'banner/masfletes_1.jpg';
        $altima = 'MasFletes_Nuestros_Artículos';
        $this->set('imagen',$imagen);
        $this->set('altima',$altima);
    }
    
    public function contacto()
    {
        $this->set('title_for_layout', 'Cont&aacute;cto');
        $this->layout = 'base';
        $imagen = 'banner/masfletes_5.jpg';
        $altima = 'MasFletes_Contáctanos';
        $this->set('imagen',$imagen);
        $this->set('altima',$altima);
        
        if ($this->request->is('post'))
        {
            if (!empty ($this->request->data))
            {
                $name = $this->data['userName'];
                $email = $this->data['userEmail'];
                if (empty($this->data['userPhone']))
                { $phone = "No proporciono ningun teléfono";}
                
                else 
                { $phone = $this->data['userPhone']; }
                $comment = $this->data['userCom'];
                $menssage = "El usuario: ".$name." generó el siguiente comentario, favor de darle "
                            . "atención lo más pronto posible. <br /><br />Los datos son: <br />Correo eléctronico: "
                            .$email.", <br /> Teléfono: ".$phone.", <br />Comentario: ".$comment."";
                
                $this->Email->to = "masfletes@masfletes.com";
                $this->Email->cc = "administrador@masfletes.com";
                $this->Email->bcc = "nayeli.ubieta@gmail.com";
                $this->Email->subject = "Notificaciones de contacto de MasFletes";
                $this->Email->from = "Contacto Mas Fletes <contacto@masfletes.com>";
                $this->Email->sendAs = 'both';
                $this->Email->smtpOptions = array (
                    'port' => '587',
                    'timeout' => '30',
                    'host' => 'mail.masdistribucion.com.mx',
                    'username' => 'admin@masdistribucion.com.mx',
                    'password' => 'distribucion2900');
                $this->Email->delivery = "smtp";
                    
                   if ($this->Email->send($menssage))
                   {
                       $this->redirect('contacto', null, true);
                   } 
                   else
                   {
                       echo $this->Email->smtpError;
                   }   
                   
            }
            
             
        }
    }
    
    public function registro()
    {
       $this->set('title_for_layout', 'Registarse'); 
       $this->layout = 'base';
       $imagen = 'banner/masfletes_3.jpg';
       $altima = 'MasFletes_Registrarse';
       $this->set('imagen',$imagen);
       $this->set('altima',$altima);
    }
    
    public function faq()
    {
       $this->set('title_for_layout', 'Preguntas Frecuentes'); 
       $this->layout = 'base';
       $imagen = 'banner/masfletes_faq.jpg';
       $altima = 'MasFletes_Faq';
       $this->set('imagen',$imagen);
       $this->set('altima',$altima);
    }
    
}

?>
